home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / utils / 4cd.zip / 4CD.BTM next >
Text File  |  1996-04-10  |  16KB  |  463 lines

  1. @echo off
  2. *if exist %TEMP\4cd.dir *del /q %TEMP\4cd.dir
  3. *set _dbpath=%@path[%@search[4cd]]
  4. *iff %1/ eq / then
  5.         *cd
  6.         *quit
  7. *endiff
  8. *iff %1/ eq /?/ then
  9.         *gosub helpinfo
  10.         *quit
  11. *endiff
  12. *iff %1/ eq /ABOUT/ then
  13.         *gosub aboutinfo
  14.         *quit
  15. *endiff
  16. :start
  17. *if %1/ eq / *quit
  18. *set _opt=%@upper[%1]
  19. *iff %@index[%_opt,/MD] ne -1 then
  20.         :mkloop
  21.         *shift
  22.         *if %1/ eq / *quit
  23.         *iff %@index[%1,/] eq -1 then
  24.                 *gosub MakeDir
  25.         *endiff
  26.         *if %@index[%1,/] eq -1 *goto /I mkloop
  27.         *goto start
  28.         *quit
  29. *elseiff %@index[%_opt,/RD] ne -1 then
  30.         :rmloop
  31.         *shift
  32.         *if %1/ eq / *quit
  33.         *iff %@index[%1,/] eq -1 then
  34.                 *gosub RemoveDir
  35.         *endiff
  36.         *if %@index[%1,/] eq -1 *goto /I rmloop
  37.         *goto start
  38.         *quit
  39. *elseiff %@index[%_opt,/SCAN] ne -1 then
  40.         *shift
  41.         *gosub Scan
  42.         *goto start
  43.         *quit
  44. *elseiff %@index[%_opt,/ADD] ne -1 then
  45.         :addloop
  46.         *shift
  47.         *if %1/ eq / *quit
  48.         *iff %@index[%1,/] eq -1 then
  49.                 *set _dr=%1
  50.                 *gosub Add
  51.         *endiff
  52.         *if %@index[%1,/] eq -1 *goto /I addloop
  53.         *goto start
  54.         *quit
  55. *elseiff %@index[%_opt,/DIRALIAS] ne -1 then
  56.         *shift
  57.         :aliasloop
  58.         *if %1/ eq / *quit
  59.         *iff %@index[%1,/] eq -1 then
  60.                 *gosub Diralias
  61.         *endiff
  62.         *if %@index[%1,/] eq -1 *goto /I aliasloop
  63.         *goto start
  64.         *quit
  65. *elseiff %@index[%_opt,/DELALIAS] ne -1 then
  66.         :delaliasloop
  67.         *shift
  68.         *if %1/ eq / *quit
  69.         *iff %@index[%1,/] eq -1 then
  70.                 *gosub DelAlias
  71.         *endiff
  72.         *if %@index[%1,/] eq -1 *goto /I delaliasloop
  73.         *goto start
  74.         *quit
  75. *elseiff %@index[%_opt,/CD] ne -1 then
  76.         *shift
  77.         *goto start
  78.         *quit
  79. *elseiff %@index[%_opt,/PWD] ne -1 then
  80.         *shift
  81.         *echo %_cwd
  82.         *goto start
  83.         *quit
  84. *elseiff %@index[%_opt,/FILE] ne -1 then
  85.         *shift
  86.         *for %_i in (@%_dbpath\4CD.SEQ) do (
  87.                 *iff %@ready[%@word["\",0,%_i]] eq 1 then
  88.                     *iff exist %_i\%1 then
  89.                         *echo ==%@char[16]               %_i\%1
  90.                         *inkey /K"YyNn" Change to this directory? (y/n) %%_ynq
  91.                         *set _ynq=%@UPPER[%_ynq]
  92.                         *iff %_ynq eq Y then
  93.                                 *cdd %_i
  94.                                 *shift
  95.                                 *unset _i _ynq
  96.                                 *goto start
  97.                         *endiff
  98.                     *endiff
  99.                 *endiff
  100.         )
  101.         *shift
  102.         *goto start
  103.         *quit
  104. *elseiff %@index[%_opt,/!FILE] ne -1 then
  105.     *shift
  106.     *for %_i in (@%_dbpath\4CD.SEQ) do (
  107.         *iff %@ready[%@word["\",0,%_i]] eq 1 then
  108.             *iff exist %_i\%1 then
  109.                 *cdd %_i
  110.                 *shift
  111.                 *unset _i
  112.                 *goto start
  113.             *endiff
  114.         *endiff
  115.     )
  116. *else
  117.         *iff isdir %1 then
  118.                 *cdd %1
  119.                 *quit
  120.         *elseiff $%1 eq $\ then
  121.                 *cdd \
  122.                 *quit
  123.         *elseiff $%1 eq $- then
  124.                 *cdd -
  125.                 *quit
  126.         *elseiff $%1 eq $* then
  127.                 *set _dest=.
  128.                 *set _dest=%@select[%_dbpath\4cd.seq,0,10,10,60,Change Directory]
  129.                 *iff $%_dest ne $ then
  130.                    *set _4dr=%@substr[%_dest,0,2]
  131.                    *iff %@removable[%_4dr] ne 1 then
  132.                       *cdd %_dest
  133.                    *else
  134.                       *do forever
  135.                          *iff %@ready[%_4dr] eq 1 then
  136.                             *iff isdir %_dest then
  137.                                *cdd %_dest
  138.                                leave
  139.                             *endiff
  140.                          *endiff
  141.                          *echo Please mount volume with %_dest in %_4dr.
  142.                          *pause
  143.                       *enddo
  144.                    *endiff
  145.                 *endiff
  146.                 *quit
  147.         *endiff
  148.         *setlocal
  149.         *echos Scanning database for "%1"...
  150.         *gosub findalias
  151.         *iff %_found eq 1 then *unset _found
  152.         *else
  153.              *FFIND /KMVT"%@UPPER[%1]" %_dbpath\4CD.SEQ > %TEMP\4CD.$$$
  154.              *for %_i in (@%TEMP\4CD.$$$) do if %@index[%@word["\",-0,%_i],%1] ne -1 echo %_i >>! %TEMP\4CD.DIR
  155.              *del /q %temp\4cd.$$$
  156.         *endiff
  157.         *echo done.
  158.         *endlocal
  159.         *iff not exist %TEMP\4cd.dir then
  160.                 *echo %1 cannot be found in the database.
  161.                 *echo You may need to regenerate the database (use %0 /SCAN),
  162.                 *echo or add a removable drive to the database (use %0 /ADD).
  163.         *elseiff %@lines[%TEMP\4cd.dir] eq 0 then
  164.                 *cdd %@line[%TEMP\4cd.dir,0]
  165.                 *del /Q %TEMP\4cd.dir
  166.         *else
  167.                 *set _dest=.
  168.                 *set _dest=%@select[%TEMP\4cd.dir,0,10,10,60,Change to "%1"]
  169.                 *iff $%_dest ne $ then
  170.                    *set _4dr=%@substr[%_dest,0,2]
  171.                    *iff %@removable[%_4dr] ne 1 then
  172.                       *cdd %_dest
  173.                    *else
  174.                       *do forever
  175.                          *iff %@ready[%_4dr] eq 1 then
  176.                             *iff isdir %_dest then
  177.                                *cdd %_dest
  178.                                leave
  179.                             *endiff
  180.                          *endiff
  181.                          *echo Please mount volume with %_dest in %_4dr.
  182.                          *pause
  183.                       *enddo
  184.                    *endiff
  185.                 *endiff
  186.                 *del /Q %TEMP\4cd.dir
  187.                 *quit
  188.         *endiff
  189.         *shift
  190.         *goto start
  191. *endiff
  192. *quit
  193.  
  194.  
  195. *rem Remove a directory and delete it from the database
  196. :RemoveDir
  197.         *iff exist %@full[%1]\*.* then
  198.                 *beep
  199.                 *echo %@upper[%@full[%1]] is not empty.  It cannot be removed.
  200.                 *quit
  201.         *endiff
  202.         *echos Removing directory %@upper[%@full[%1]]...
  203.         *rd %@full[%1]
  204.         *echo done.
  205.         *echos Updating database...
  206.         *move /Q %_dbpath\4cd.seq %TEMP\4cd.old
  207.         *setlocal
  208.         *set _dbhandle=%@fileopen[%TEMP\4CD.OLD,READ]
  209.         *if %_dbhandle eq -1 *goto dberror
  210.         *set _newhandle=%@fileopen[%_dbpath\4CD.SEQ,WRITE]
  211.         *if %_newhandle eq -1 *goto dberror
  212.         *set _curln=%@fileread[%_dbhandle]
  213.         do until "%_curln" eq "**EOF**"
  214.                 *iff %@upper[%1] ne %@upper[%_curln] then
  215.                         *set _err=%@filewrite[%_newhandle,%_curln]
  216.                 *endiff
  217.                 set _curln=%@fileread[%_dbhandle]
  218.         *enddo
  219.         *set _dbhandle=%@fileclose[%_dbhandle]
  220.         *if %_dbhandle eq -1 *goto dberror
  221.         *set _newhandle=%@fileclose[%_newhandle]
  222.         *if %_newhandle eq -1 *goto dberror
  223.         *del /Q %TEMP\4cd.old
  224.         *echo done.
  225.         *endlocal
  226. *return
  227.  
  228.  
  229. *rem Create a new directory and add it to the database
  230. :MakeDir
  231.         *echos Creating %@upper[%@full[%1]]...
  232.         *md %@full[%1]
  233.         *echo done.
  234.         *echos Updating database...
  235.         *echo %@full[%1] >>! %_dbpath\4cd.seq
  236.         *echo done.
  237. *return
  238.  
  239.  
  240. *rem Regenerate the database
  241. :Scan
  242.         *if exist %_dbpath\4cd.seq *del /Q %_dbpath\4cd.seq
  243.         *echo Scanning drives for directories...
  244.         *for %i in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
  245.            *set _dr=%i:
  246.            *gosub Add
  247.         )
  248.         *echo done.
  249.         *echo Database created.
  250. *return
  251.  
  252. *rem Add a drive to the database
  253. :Add
  254.         *iff %@ready[%_dr] eq 1 then
  255.         *echos     Adding %_dr to database...
  256.            *dir/efsba:d %_dr\ >>! %_dbpath\4cd.seq
  257.         *echo done.
  258.         *endiff
  259. *return
  260.  
  261.  
  262. *rem Create a new alias for a directory.
  263. :Diralias
  264.         *setlocal
  265.         *iff not exist %_dbpath\4cd.als then
  266.                 *echo %@upper[%1] %@upper[%2] >! %_dbpath\4cd.als
  267.         *else
  268.                 *move /q %_dbath\4cd.als %temp\4cdals.old
  269.                 *set _aliashandle=%@fileopen[%temp\4CDALS.OLD,READ]
  270.                 *if %_aliashandle eq -1 *goto dberror
  271.                 *set _newhandle=%@fileopen[%_dbpath\4CD.ALS,WRITE]
  272.                 *if %_newhandle eq -1 *goto dberror
  273.                 *set _written=0
  274.                 *do until "%_curln" eq "**EOF**"
  275.                         *set _curln=%@fileread[%_aliashandle]
  276.                         *iff %@upper[%1] eq %@upper[%@word[0,%_curln]] then
  277.                                 *set _err=%@filewrite[%_newhandle, %@upper[%1] %@upper[%2]]
  278.                                 *if %_err eq -1 goto dberror
  279.                                 *set _written=1
  280.                         *else
  281.                                 *set _err=%@filewrite[%_newhandle,%_curln]
  282.                                 *if %_err eq -1 goto dberror
  283.                         *endiff
  284.                 *enddo
  285.                 *iff %_written eq 0 then
  286.                         *set _err=%@filewrite[%_newhandle,%@upper[%1] %@upper[%2]]
  287.                 *endiff
  288.                 *set _aliashandle=%@fileclose[%_aliashandle]
  289.                 *if %_aliashandle eq -1 *goto dberror
  290.                 *set _newhandle=%@fileclose[%_newhandle]
  291.                 *if %_newhandle eq -1 *goto dberror
  292.                 *shift
  293.                 *shift
  294.         *endiff
  295.         *if exist %temp\4cdals.old *del /q %temp\4cdals.old
  296.         *endlocal
  297. *return
  298.  
  299.  
  300. *rem Delete an alias for a directory.
  301. :delalias
  302.         *setlocal
  303.         *move /q %_dbpath\4cd.als %temp\4cdals.old
  304.         *set _oldhandle=%@fileopen[%temp\4CDALS.OLD,READ]
  305.         *if %_oldhandle eq -1 *goto dberror
  306.         *set _newhandle=%@fileopen[%_dbpath\4CD.ALS,WRITE]
  307.         *if %_newhandle eq -1 *goto dberror
  308.         *set _currln=%@fileread[%_oldhandle]
  309.         *do until "%_currln" eq "**EOF**"
  310.                 *iff %@upper[%@word[0,%_currln]] ne %@upper[%1] then
  311.                         *set _err=%@filewrite[%_newhandle,%_currln]
  312.                         *if %_err eq -1 goto dberror
  313.                 *endiff
  314.                 *set _currln=%@fileread[%_oldhandle]
  315.         *enddo
  316.         *set _oldhandle=%@fileclose[%_oldhandle]
  317.         *if %_oldhandle eq -1 *goto dberror
  318.         *set _newhandle=%@fileclose[%_newhandle]
  319.         *if %_newhandle eq -1 *goto dberror
  320.         *del /q %temp\4cdals.old
  321.         *endlocal
  322. *return
  323.  
  324. *rem Search the alias database for the chosen directory
  325. :findalias
  326.         *if not exist %_dbpath\4cd.als *return
  327.         *set _found=0
  328.         *set _dbhandle=%@fileopen[%_dbpath\4CD.ALS,READ]
  329.         *if %_dbhandle eq -1 *goto dberror
  330.         *set _currln=%@fileread[%_dbhandle]
  331.         *do until "%_currln" eq "**EOF**"
  332.                 *iff %@upper[%1] eq %@upper[%@word[0,%_currln]] then
  333.                         *echo %@word[1,%_currln] >> %temp\4cd.dir
  334.                         *set _found=1
  335.                 *endiff
  336.                 *iff %_found ne 1 then
  337.                         *set _currln=%@fileread[%_dbhandle]
  338.                 *else
  339.                         *goto closefiles
  340.                 *endiff
  341.         *enddo
  342.         :closefiles
  343.         *set _dbhandle=%@fileclose[%_dbhandle]
  344.         *if %_dbhandle eq -1 *goto dberror
  345. *return
  346.  
  347. *rem Help information
  348. :helpinfo
  349. cls
  350. *text
  351. Usage: 4CD [/MD | /RD | [/CD] dir [...]]
  352.                 Create, remove, and change directories
  353.  
  354.         /MD     Create the directories whose names follow, until the next
  355.                 switch
  356.         /RD     Remove the directories whose names follow, until the next
  357.                 switch
  358.         /CD     Change the current directory to the one whose name follows.
  359.                 /CD is optional if it is the first switch on the line.
  360.  
  361.         If no arguments are supplied to 4CD, the current working directory
  362.         will be displayed.
  363.  
  364.         dir     is the name of a directory or directory alias (see below).
  365.  
  366. Usage: 4CD -    Change back to the directory you were in when you last issued
  367.                 a CD, CDD, or 4CD command
  368.  
  369. Usage: 4CD *    Select a directory to change to from a scrolling list.
  370.  
  371. endtext
  372. *pause
  373. *cls
  374. *text
  375. Usage: 4CD /FILE filename
  376.                 Search for the file specified and change to the directory
  377.                 it is found in.  You are asked whether you want to change
  378.                 to the indicated directory.
  379.  
  380. Usage: 4CD /!FILE filename
  381.                 As 4CD /FILE, except that the change is automatic to the
  382.                 directory in which the file is first found.
  383.  
  384. endtext
  385. *pause
  386. *cls
  387. *text
  388. Usage: 4CD /DIRALIAS alias dir [...]    Attach an alias to a directory
  389.  
  390.                 alias   is the alias (nickname) that you want to attach
  391.                         to the directory.
  392.  
  393.                 dir     is the directory to attach the alias to.  It
  394.                         should be a full specification (i.e., include
  395.                         the drive and all higher level directories).
  396.  
  397.  
  398. Usage: 4CD /DELALIAS alias [...]        Delete a directory alias
  399.  
  400.                 alias   is the directory alias to remove from the alias list.
  401.  
  402.  
  403. endtext
  404. *pause
  405. *cls
  406. *text
  407. Usage: 4CD /SCAN                        Rescan disks for directories.
  408.                                         Only drives C: through Z: will be
  409.                                         scanned.  Removable drives, including
  410.                                         CD-ROMs, which are currently mounted
  411.                                         will be scanned.
  412.  
  413. Usage: 4CD /ADD d: [...]                Add one or more drives to the
  414.                                         database.  You may add drives
  415.                                         A: and B:, or add additional
  416.                                         removable media (ZIP, JAZZ, 
  417.                                         EZ-DRIVE, CD-ROM, etc.) using 
  418.                                         this option.
  419.  
  420. Usage: 4CD /PWD                         Display the current directory.
  421.  
  422. endtext
  423. *pause
  424. *cls
  425. *text
  426.  
  427.         Any number of commands may be combined on a single line,
  428.         in any order.
  429.  
  430.         Deleting a directory alias does not remove the directory, and
  431.         removing the directory does not remove any aliases referring to
  432.         that directory.
  433. endtext
  434. *return
  435.  
  436. :aboutinfo
  437. *text
  438.         4CD was written by Jeff Zeitlin to see if it could be done.
  439.         I can be contacted in the ILink Shareware and 4DOS conferences,
  440.         or via Internet at jeff.zeitlin@execnet.com or in the
  441.         comp.os.msdos.4dos newsgroup.
  442.  
  443.         4CD is copyright 1993-1996 Jeff Zeitlin. All rights reserved.
  444.         4CD may be shared with users of 4DOS and compatible command
  445.         processors, as long as this ABOUT information and copyright
  446.         notice remain included and unaltered.  If you think it's worth
  447.         paying for, contact me at one of the above electronic
  448.         locations.
  449. endtext
  450. *return
  451.  
  452. :dberror
  453. *text
  454.         An error has occurred trying to access the directory database.
  455.         It may be in use by another copy of 4CD, or another program.
  456.         Please make sure that no other program and no other copy of 4CD
  457.         is attempting to use the directory database.  If no other
  458.         program and no other copy of 4CD is trying to use the directory
  459.         database, your FILES setting in CONFIG.SYS is probably too
  460.         small, or some other problem with file handles exists.  Please
  461.         correct the problem and retry 4CD.
  462. endtext
  463.